package com.tsingtree.modular.controller.view;

import com.tsingtree.base.auth.annotion.Permission;
import com.tsingtree.base.pojo.page.LayuiPageInfo;
import com.tsingtree.modular.entity.NanSellAnnounce;
import com.tsingtree.modular.entity.NanUser;
import com.tsingtree.modular.model.params.NanSellAnnounceParam;
import com.tsingtree.modular.service.NanSellAnnounceService;
import com.tsingtree.modular.service.NanUserService;
import com.tsingtree.roses.core.base.controller.BaseController;
import com.tsingtree.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 社区控制器
 *
 * @author jagger
 */
@Controller
@RequestMapping("/nanSellAnnounce")
public class NanSellAnnounceController extends BaseController {

    private String PREFIX = "/nanSellAnnounce";

    @Autowired
    private NanSellAnnounceService nanSellAnnounceService;
    @Autowired
    private NanUserService nanUserService;

    /**
     * 跳转到主页面
     *
     * @author jagger
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/nanSellAnnounce.html";
    }

    /**
     * 新增页面
     *
     * @author jagger
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/nanSellAnnounce_add.html";
    }

    /**
     * 新增官方帖子页面
     *
     * @author claude
     */
    @RequestMapping("/addOfficial")
    public String addOfficial() {
        return PREFIX + "/nanSellAnnounce_addOfficial.html";
    }

    /**
     * 编辑页面
     *
     * @author jagger
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/nanSellAnnounce_edit.html";
    }
    @RequestMapping("/editSort")
    public String editSort() {
        return PREFIX + "/nanSellAnnounce_editSort.html";
    }

    /**
     * 新增接口
     *
     * @author jagger
     */
    @RequestMapping("/addItem")
    @Permission
    @ResponseBody
    public ResponseData addItem(NanSellAnnounceParam nanSellAnnounceParam) {
        this.nanSellAnnounceService.add(nanSellAnnounceParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author jagger
     */
    @RequestMapping("/editItem")
    @Permission
    @ResponseBody
    public ResponseData editItem(NanSellAnnounceParam nanSellAnnounceParam) {
        this.nanSellAnnounceService.update(nanSellAnnounceParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author jagger
     */
    @RequestMapping("/delete")
    @Permission
    @ResponseBody
    public ResponseData delete(NanSellAnnounceParam nanSellAnnounceParam) {
        nanSellAnnounceParam.setIsDel(true);
        this.nanSellAnnounceService.update(nanSellAnnounceParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author jagger
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(NanSellAnnounceParam nanSellAnnounceParam) {
        NanSellAnnounce detail = this.nanSellAnnounceService.getById(nanSellAnnounceParam.getId());
        NanUser user = nanUserService.getById(detail.getUserId());
        detail.setSellerName(user.getNickName());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author jagger
     */
    @ResponseBody
    @Permission
    @RequestMapping("/list")
    public LayuiPageInfo list(NanSellAnnounceParam nanSellAnnounceParam) {
        return this.nanSellAnnounceService.findPageBySpec(nanSellAnnounceParam);
    }

}


